package org.ah.ai.main;
import java.util.Date;
import org.ah.ai.bean.AiResult;
import org.ah.ai.util.ImgUtil;
import org.junit.Test;
import cn.xsshome.taip.imageclassify.TAipImageClassify;
import cn.xsshome.taip.ptu.TAipPtu;
import cn.xsshome.taip.util.FileUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AiTest {
	// 设置APPID/APP_KEY
	public static final String APP_ID = "2116659786";
	public static final String APP_KEY = "hx2DCPSVuS5bqZEn";
	@Test
	public void test_P图() throws Exception {
		String imagePath = "D:\\DocumentsFiles\\face2.jpg";
		int dot = imagePath.lastIndexOf(".");
		String prefix = imagePath.substring(0, dot);
		String suffix = imagePath.substring(dot);
		long code = new Date().getTime();
		String saveImg = prefix + "_" + code + suffix;
		System.out.println(saveImg);
		TAipPtu aipPtu = new TAipPtu(APP_ID, APP_KEY);
		// String result = aipPtu.faceCosmetic(imagePath, 23);//人脸美妆
		// 人脸变妆——https://ai.qq.com/doc/facedecoration.shtml
		String result = aipPtu.faceDecoration(imagePath, 22);
		// String result = aipPtu.imgFilter(imagePath, 20);//滤镜 天天P图
		// String result = aipPtu.faceSticker(imagePath, 27);// 大头贴
		System.out.println(result);
		// 从字符串读取
		ObjectMapper mapper = new ObjectMapper();
		AiResult obj = mapper.readValue(result, AiResult.class);
		String imgCode = obj.getData().getImage();
		ImgUtil.decodeImg(imgCode, saveImg);
	}
	@Test
	public void testAi识别() throws Exception {
		String filePath = "D:\\DocumentsFiles\\face2.jpg";
		// 初始化一个TAipImageClassify
		TAipImageClassify aipImageClassify = new TAipImageClassify(APP_ID,
				APP_KEY);
		byte[] image = FileUtil.readFileByBytes(filePath);// 获取文件的byte数据
		String result = aipImageClassify.imageTag(image);// 图像标签识别
		// String result = aipImageClassify.imageFood(image);// 美食图片识别
		System.out.println(result);
		// 从字符串读取
		ObjectMapper mapper = new ObjectMapper();
		AiResult obj;
		obj = mapper.readValue(result, AiResult.class);
		System.out.println(obj.getData().getTag_list());
	}
}